import EventSystem from "../gameSwitch/startGame";
import AddScoreNode from "./AddScore";
import { Constant } from "../constant/Constant";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    @property(cc.Node)
    eventSys: cc.Node = null;
    @property(cc.Node)
    scoreAddNode: cc.Node = null;


    start() {

    }

    onCollisionEnter(other: cc.Component) {
        let thisSco = Constant.NOW_SCORE;
        if (other.node.name == "Left" || other.node.name == "Right") {
            if (thisSco > Constant.PLAYER_SCORE) Constant.PLAYER_SCORE = thisSco;//记录最高分数
            this.eventSys.getComponent(EventSystem).gameFailed();
        }
    }

    onCollisionExit(other: cc.Node) {
        // cc.log("exit" + other.name);
        // let name = other.name;
        // if (name == "left" || name == "right") {
        //     cc.log("exit");
        // }
    }

    onCollisionStay(other: cc.Node) {
        // cc.log("stay" + other.name);
        // let name = other.name;
        // if (name == "left" || name == "right") {
        //     cc.log("stay");
        // }
    }

    // update (dt) {}
}
